package com.soft.javase.day06.string;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/24
 */
public class StringDemo2 {
    public static void main(String[] args) {

        String[] arr = {"nba", "abc", "cba", "zz", "qq", "haha"};

        System.out.println("排序前:");
        System.out.println(Arrays.toString(arr));

        Arrays.sort(arr);

        System.out.println("排序后:");
        System.out.println(Arrays.toString(arr));


        String[] arr1 = {"nba", "abc", "cba", "zz", "qq", "haha"};
        // 使用Comparator比较器
        Arrays.sort(arr1, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                return s1.compareTo(s2); // 字典顺序比较
            }
        });

        System.out.println("使用Comparator比较器:"+Arrays.toString(arr1));
    }

}
